home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / SAMDU240.ZIP / HANDLEST.C < prev    next >
Text File  |  1993-10-01  |  29KB  |  548 lines

  1. /*********************************************************************/
  2. /*                                                                   */
  3. /*    Name:    HANDLEST.C                                            */
  4. /*                                                                   */
  5. /*    Copyright (c) Stewart A. Berman 1992, All rights reserved      */
  6. /*                                                                   */
  7. /*********************************************************************/
  8. #pragma warning (disable:4001)
  9. #include <Windows.h>
  10. #pragma warning (default:4001)
  11.  
  12. #include <String.h>
  13.  
  14. #include "HandleSt.h"
  15. #include "IOStatus.h"
  16.  
  17. #ifdef DEBUG
  18. #include "DebugOut.h"
  19. #endif
  20.  
  21. #ifdef _cplusplus
  22. extern "C" {
  23. #endif /* _cplusplus */
  24.  
  25. BOOL bTimerInterval ;
  26.  
  27. int  FAR PASCAL HandleStatus ( UINT nStatus1, UINT nStatus2, UINT nParam1, UINT nParam2, LONG lParam1, LONG lParam2 )
  28. {
  29. /********************************************************************/
  30. /*                                                                  */
  31. /* This is the callback function for disk activity status           */
  32. /*                                                                  */
  33. /* 1. Determine the type of callback (based on nStatus1)            */
  34. /*                                                                  */
  35. /* nStatus                  Action                                  */
  36. /* -------                  ------                                  */
  37. /* STATUS1_INIT              Save hWnd and hInstance                */
  38. /* STATUS1_START             Send USR_ACTIVE message                */
  39. /* STATUS1_BOOT_SECTOR       Send USR_ACTIVE message                */
  40. /* STATUS1_DIRECTORY         Send USR_ACTIVE message                */
  41. /* STATUS1_FAT               Send USR_ACTIVE message                */
  42. /* STATUS1_SYSTEM_FILE       Send USR_ACTIVE message                */
  43. /* STATUS1_CYLINDER          Send USR_UPDATE message                */
  44. /* STATUS1_HEAD              Ignore                                 */
  45. /* STATUS1_END               Beep and/or Flash if option selected   */
  46. /* STATUS1_ERROR             Error type dependent                   */
  47. /*                                                                  */
  48. /********************************************************************/
  49.  
  50.     static BOOL bFlash = FALSE ;
  51.     static BOOL bSound = FALSE ;
  52.  
  53.     static HINSTANCE hInstance = NULL ;
  54.  
  55.     static HWND      hWnd      = NULL;
  56.  
  57.     static UINT nTimerInterval ;
  58.  
  59.     static TIMERPROC lpfnSABDUTimerFunc ;
  60.  
  61.     char czBuffer1[512] ;
  62.     char czBuffer2[512] ;
  63.  
  64.     char czIconMessage[512] ;
  65.     char czNormalMessage[512] ;
  66.  
  67.     STMESSAGE stMessage ;
  68.     STMESSAGE far *lpstMessage ;
  69.  
  70.     MSG msg ;
  71.  
  72. /********************************************************************/
  73. /*                                                                  */
  74. /* We want to be a well behaved Windows application so we need to   */
  75. /* let go of the CPU and let other applications get some work done. */
  76. /*                                                                  */
  77. /********************************************************************/
  78.  
  79.     while ( PeekMessage ( &msg, NULL, NULL, NULL, PM_REMOVE ) )
  80.           {
  81.           TranslateMessage ( &msg ) ;
  82.           DispatchMessage  ( &msg ) ;
  83.           }
  84.  
  85. /********************************************************************/
  86. /*                                                                  */
  87. /* The following is a multilevel switch for processing callback     */
  88. /* requests.                                                        */
  89. /*                                                                  */
  90. /* The first level is seperates the major areas.  Most of them are  */
  91. /* normal operation and are provided so the application can keep    */
  92. /* the user informed on the progress of long running tasks.         */
  93. /* Most of the first level messages are sent via SendMessage.       */
  94. /* The response is passed back to the routine issuing the callback  */
  95. /* requests.  This allows the application to stop a long running    */
  96. /* process by returning an IDCANCEL in response to the SendMessage  */
  97. /* request.                                                         */
  98. /*                                                                  */
  99. /* The second level is used to seperate the various types of error  */
  100. /* notifications.  Some of them prompt the user for a decision as   */
  101. /* to whether or not a retry should be attempted.  Others simply    */
  102. /* notify the user of a problem.                                    */
  103. /*                                                                  */
  104. /* The general method used to kept the user informed is to update   */
  105. /* two messages used by our WM_PAINT routine.  One is used when the */
  106. /* application is running in Iconic state and the other is for when */
  107. /* it is not running in Iconic state.  The messages are built here  */
  108. /* and passed in a structure via a SendMessage call to a routine    */
  109. /* that stores them where the WM_PAINT routine can access them.     */
  110. /* This maintains complete independence between this routine and    */
  111. /* the WM_PAINT routine.                                            */
  112. /*                                                                  */
  113. /********************************************************************/
  114.  
  115. #ifdef DEBUG
  116.     if ( pCDebugOut!=NULL )
  117.        {
  118.        wsprintf (
  119.                  (LPSTR)DebugOutczDebugBuffer(),
  120.                  (LPSTR)"Status1: %4.4X\n"
  121.                         "Status2: %4.4X\n"
  122.                         "nParam1: %4.4X\n"
  123.                         "nParam2: %4.4X\n"
  124.                         "lParam1: %8.8lX\n"
  125.                         "lParam2: %8.8lX",
  126.                  nStatus1,
  127.                  nStatus2,
  128.                  nParam1,
  129.                  nParam2,
  130.                  lParam1,
  131.                  lParam2
  132.                 ) ;
  133.        DebugOutOutputIf ( 0x00000001, DebugOutczDebugBuffer(), "HandleStatus", MB_ICONINFORMATION|MB_OK ) ;
  134.        }
  135. #endif
  136.  
  137.     switch ( nStatus1 )
  138.        {
  139.        case STATUS1_INIT:              /* User is passing hWnd, hInstance, and timer controls */
  140.           {
  141.           hWnd      = (HWND)nParam1 ;
  142.           hInstance = (HINSTANCE)nParam2 ;
  143.           nTimerInterval = LOWORD ( lParam1 ) ;
  144.           bFlash = HIWORD ( lParam2 ) ;
  145.           bSound = LOWORD ( lParam2 ) ;
  146.           return ( FALSE ) ;
  147.           break ;
  148.           }
  149.        case STATUS1_START:             /* We are starting a long running process */
  150.           {
  151.           wsprintf ( (LPSTR)czIconMessage,   (LPCSTR)"%2.2d  %3.2d%%", 0, 0 ) ;
  152.           stMessage.pIconMessage = czIconMessage ;
  153.           wsprintf ( (LPSTR)czNormalMessage, (LPCSTR)"Cylinder %2.2d (%3.2d%%)", 0, 0 ) ;
  154.           stMessage.pNormalMessage = czNormalMessage ;
  155.           stMessage.nPercentageToColor = 0 ;
  156.           lpstMessage = (STMESSAGE far *) &stMessage ;
  157.           return ( LOWORD (SendMessage ( hWnd, USR_ACTIVE, 0, (LONG)lpstMessage ) ) ) ;
  158.           break ;
  159.           }
  160.        case STATUS1_BOOT_SECTOR:       /* We are installing a new boot sector */
  161.           {
  162.           _fstrcpy ( (LPSTR)czIconMessage,   (LPCSTR)"Boot" ) ;
  163.           stMessage.pIconMessage = czIconMessage ;
  164.           _fstrcpy ( (LPSTR)czNormalMessage, (LPCSTR)"Installing Boot Sector" ) ;
  165.           stMessage.pNormalMessage = czNormalMessage ;
  166.           stMessage.nPercentageToColor = 100 ;
  167.           lpstMessage = (STMESSAGE far *) &stMessage ;
  168.           return ( LOWORD ( SendMessage ( hWnd, USR_ACTIVE, 0, (LONG)lpstMessage ) ) ) ;
  169.           break ;
  170.           }
  171.        case STATUS1_DIRECTORY:         /* We are building a diskette directory */
  172.           {
  173.           _fstrcpy ( (LPSTR)czIconMessage,   (LPCSTR)"DIR" ) ;
  174.           stMessage.pIconMessage = czIconMessage ;
  175.           _fstrcpy ( (LPSTR)czNormalMessage, (LPCSTR)"Creating Directory" ) ;
  176.           stMessage.pNormalMessage = czNormalMessage ;
  177.           stMessage.nPercentageToColor = 100 ;